package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.entity.NursingPlanXZ;
import com.zzyl.mapper.NursingPlanMapper;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class NursingPlanServiceImpl implements NursingPlanService {

    @Autowired
    private NursingPlanMapper nursingPlanMapper;

//    查看全部计划
    @Override
    public List<NursingPlan> getPlan() {
        return nursingPlanMapper.selectAll();
    }

//    分页查询
    @Override
    public PageResponse<NursingPlanVo> search(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingPlanVo> nursingPlanVo = nursingPlanMapper.search(name , status);
        return PageResponse.of(nursingPlanVo, NursingPlanVo.class);
    }

    @Override
    public void add(NursingPlanXZ nursingPlanXZ) {
        NursingPlan nursingPlan = new NursingPlan();
        BeanUtils.copyProperties(nursingPlanXZ , nursingPlan);
        nursingPlan.setUpdateTime(LocalDateTime.now());
        nursingPlan.setCreateTime(LocalDateTime.now());
        nursingPlanMapper.insert(nursingPlan);

    }

    //    根据id查询
    @Override
    public NursingPlan getById(Integer id) {
        NursingPlan nursingPlan = nursingPlanMapper.selectById(id);
        return nursingPlan;
    }

//    修改护理计划
    @Override
    public void update(NursingPlanXZ nursingPlanXZ) {
        NursingPlan nursingPlan = BeanUtil.toBean(nursingPlanXZ, NursingPlan.class);
        nursingPlan.setUpdateTime(LocalDateTime.now());
//        nursingPlan.setCreateTime(LocalDateTime.now());
        nursingPlanMapper.update(nursingPlan);
    }

    //    根据id删除
    @Override
    public void delete(Integer id) {
        nursingPlanMapper.deleteById(id);
    }

    @Override
    public int updateStatusById(Integer id, Integer status) {

        return nursingPlanMapper.updateStatusById(id , status);
    }
}
